<template>
  <div class="hello">
    <h1>{{isLogin}}</h1>
    <p>{{token}}</p>
    <p>{{photo}}</p>
    <p>{{username}}</p>
    <a href="javascript:;" @click="login">点击</a>
    <a href="javascript:;" @click="logout">点击</a>
    <router-link to="index">点击</router-link>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'

  export default {
    name: 'indes',
    data () {
      return {
        msg: 'Welcome to Your Vue.js App',
      }
    },
    methods: {
      logout () {
        this.$store.dispatch('logout')

      },
//    18670096039
      login () {
        this.params = {
          'mobile': '18670096039',
          'password': '123456'
        }
        this.$post('/user/login', this.params).then(response => {
          let r = response.data
          let user = {
            'token': r.data.token
          }
          this.$store.dispatch('login', user)
          user = {
            'username': 'admin',
            'photo': 'www.baodu.com'
          }
          this.$store.dispatch('updateUserInfo', user)
        })
      }
    },
    mounted () {
    },
    computed: {
      ...mapGetters({
        isLogin: 'isLogin',
        username: 'username',
        photo: 'photo',
        token: 'token'
      })
    }
  }
</script>

